package com.qidianit.mes.device.controller;


import com.qidianit.common.pojo.MESResult;
import com.qidianit.mes.device.service.DeviceMainPlanService;
import com.qidianit.mes.device.vo.DeviceMainPlanOfItem;
import com.qidianit.mes.device.vo.DeviceMainPlanOfLedger;
import com.qidianit.mes.pojo.DeviceMainPlan;
import com.qidianit.mes.pojo.DeviceMaintainItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

@RestController
@RequestMapping("/deviceMainPlan")
@CrossOrigin
public class DeviceMainPlanController {


    @Autowired
    DeviceMainPlanService deviceMainPlanService;

    @GetMapping("/list")
    public MESResult list(String planCode, String planName, String planType,String planStatus,
                          @RequestParam(defaultValue = "1")int page,
                          @RequestParam(defaultValue = "10")int limit) {
        MESResult mesResult = deviceMainPlanService.list(planCode,planName,planType,planStatus,page,limit);
        return mesResult;
    }
    @GetMapping("/listItemsByPlanId")
    public MESResult listItems(String planCode,
                          @RequestParam(defaultValue = "1")int page,
                          @RequestParam(defaultValue = "10")int limit) {
        MESResult mesResult = deviceMainPlanService.listItemsByPlanId(planCode,page,limit);
        return mesResult;
    }
    @GetMapping("/listLedgersByPlanId")
    public MESResult listLedgers(String planCode,
                               @RequestParam(defaultValue = "1")int page,
                               @RequestParam(defaultValue = "10")int limit) {
        MESResult mesResult = deviceMainPlanService.listledgersByPlanId(planCode,page,limit);
        return mesResult;
    }

    @PostMapping("/add")
    public MESResult add(@RequestBody DeviceMainPlan deviceMainPlan){
        return deviceMainPlanService.add(deviceMainPlan);
    }
    @PostMapping("/edit")
    public MESResult edit(@RequestBody DeviceMainPlan deviceMainPlan){
        return deviceMainPlanService.edit(deviceMainPlan);
    }
    @DeleteMapping("/delete")
    public MESResult delete(String id){
        return deviceMainPlanService.delete(id);
    }

    @PostMapping("/addPlanOfItem")
    public MESResult addPlanOfItem(@RequestBody DeviceMainPlanOfItem mainPlanOfItem){
        return deviceMainPlanService.addMainPlanOfItem(mainPlanOfItem);
    }

    @PostMapping("/addPlanOfledger")
    public MESResult addPlanOfledger(@RequestBody DeviceMainPlanOfLedger deviceMainPlanOfLedger){
        return deviceMainPlanService.addMainPlanOfLedger(deviceMainPlanOfLedger);
    }

    @PostMapping("/deletePlanOfItem")
    public MESResult deletePlanOfItem(@RequestBody DeviceMainPlanOfItem mainPlanOfItem){
        return deviceMainPlanService.deleteMainPlanOfItem(mainPlanOfItem);
    }

    @PostMapping("/deletePlanOfledger")
    public MESResult deletePlanOfledger(@RequestBody DeviceMainPlanOfLedger deviceMainPlanOfLedger){
        return deviceMainPlanService.deleteMainPlanOfLedger(deviceMainPlanOfLedger);
    }

}
